package org.jweb.demo.controller;

import org.jweb.core.bean.PageMode;
import org.jweb.core.bean.ReplyDataMode;
import org.jweb.core.util.StringUtil;
import org.jweb.core.web.controller.BaseController;
import org.jweb.demo.service.DemoGoodsTypeServiceI;
import org.jweb.demo.trans.form.DemoGoodsTypeDicSaveForm;
import org.jweb.demo.trans.form.DemoGoodsTypeDicSearchForm;
import org.jweb.demo.trans.vo.DemoGoodsTypeDicVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/API/demoGoodsTypeAPI")
public class DemoGoodsTypeController extends BaseController {
	@Autowired
	private DemoGoodsTypeServiceI demoGoodsTypeService;
	
	@RequestMapping(params = "list")
	@ResponseBody
	public ReplyDataMode list(DemoGoodsTypeDicSearchForm searchForm){
		ReplyDataMode j = new ReplyDataMode();
		
		searchForm.emptyValue2NullValue();
		PageMode<DemoGoodsTypeDicVO> voli = this.demoGoodsTypeService.list(searchForm,1,10);
		
		j.setSuccess(true);
		j.setData(voli);
		
		return j;
	}
	
	@RequestMapping(params = "get")
	@ResponseBody
	public ReplyDataMode get(String goodsTypeId){
		ReplyDataMode j = new ReplyDataMode();
		
		DemoGoodsTypeDicVO vo= this.demoGoodsTypeService.get(goodsTypeId);
		
		j.setSuccess(true);
		j.setData(vo);
		
		return j;
	}
	
	@RequestMapping(params = "saveForm")
	@ResponseBody
	public ReplyDataMode saveForm(DemoGoodsTypeDicSaveForm saveForm){
		ReplyDataMode j = new ReplyDataMode();
		
		if(StringUtil.isNotEmpty(saveForm.getId())){
			this.demoGoodsTypeService.update(saveForm);
			
		} else {
			this.demoGoodsTypeService.add(saveForm);
		}
		
		
		j.setSuccess(true);
		
		return j;
	}
	
	
	
	
	
	
}
